﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Processing001.Library.Interfaces;

namespace Processing001.Library
{
    public sealed class ComplexNumber : INumbers<ComplexNumber>
    {
        private double image;
        private double real;

        #region [  Implements ComplexNumber  ]

        public ComplexNumber Add(ComplexNumber number)
        {
            return new ComplexNumber(Real + number.real, Image + number.image);
        }

        public ComplexNumber Sub(ComplexNumber number)
        {
            return new ComplexNumber(Real - number.real, Image - number.image);
        }

        public ComplexNumber Div(ComplexNumber number)
        {
            return new ComplexNumber((Real * number.Real + Image * number.Image) / (Real * number.Real - Image * number.Image), (number.Real * Image - Real * number.Image) / (Real * number.Real - Image * number.Image));
        }

        public ComplexNumber Mul(ComplexNumber number)
        {
            return new ComplexNumber(Real * number.Real - Image * number.Image, Real * number.Image + number.Real * Image);
        }

        #endregion

        public ComplexNumber()
        {
        }

        public ComplexNumber(double real, double image)
        {
            this.image = image;
            this.real = real;
        }

        public double Image
        {
            get { return image; }
            set { image = value; }
        }

        public double Real
        {
            get { return real; }
            set { real = value; }
        }

        public ComplexNumber ToInvolve()
        {
            return new ComplexNumber(real, -image);
        }
    }
}
